import Vue from "vue";
import Vuex from "vuex";
import app from "./modules/app";
import user from "./modules/user";
import tagsView from "./modules/tagsView";
import permission from "./modules/permission";
import settings from "./modules/settings";
import getters from "./getters";
import { getMap } from "@/api/enum";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    enums: {},
    dicts: {},
  },
  mutations: {
    setEnums(state, enums) {
      state.enums = enums;
    },
    setDicts(state, dicts) {
      state.dicts = dicts;
    },
  },
  actions: {
    // 获取枚举值
    async getMap({ commit }) {
      const res = await getMap();

      if (res.code === "200" || res.code === 200) {
        commit("setEnums", res.data.enums);
        commit("setDicts", res.data.dicts);
      }
    },
  },
  modules: {
    app,
    user,
    tagsView,
    permission,
    settings,
  },
  getters,
});

export default store;
